#include "ScoringVector.h"

// ScoringVector - default constructor
ScoringVector::ScoringVector() : PositionalScoreElection() {}

// ScoringVector
ScoringVector::ScoringVector( const set<string>& candidates ) : PositionalScoreElection( candidates ) {}

// ScoringVector
ScoringVector::ScoringVector( const set<string>& candidates, const multiset< RationalVote >& votes ) : PositionalScoreElection ( candidates, votes ) {}

// set_scoring_vector
void ScoringVector::set_scoring_vector( vector<unsigned int> scoring_vector ) {
    // sort the numbers
    multiset<int> temp( scoring_vector.begin(), scoring_vector.end() );
    scoring_vector_.clear();
    // reverse the sort
    scoring_vector_ = vector<unsigned int>( temp.rbegin(), temp.rend() );
    clear_scores();
    if( votes_.size() ) {
        count_votes();
    }
}

// get_scoring_vector
vector<unsigned int> ScoringVector::get_scoring_vector() const {
    return scoring_vector_;
}

// position_score
unsigned int ScoringVector::position_score( unsigned int position ) const {
    if( position >= scoring_vector_.size() ) {
        return 0;
    } else {
        return scoring_vector_[position];
    }
}

void ScoringVector::interactive() {
    vector<unsigned int> scores;
    unsigned int n;
    cout << "Enter numbers to put into the scoring vector and 0 to finish: ";
    //TODO: Error check
    while ( cin >> n && n > 0 ) {
        scores.push_back( n );
    }
    set_scoring_vector( scores );
    scores = get_scoring_vector();
    vector<unsigned int>::iterator i = scores.begin();
    while( i != scores.end() ) {
        cout << *i << " ";
        ++i;
    }
    cout << "\n";
}
